package comvecspace.data.model.sql;

/**
 * 数据类型
 */
public enum TDataType {
	ftUnkown,
	ftString,
	ftByte,
	ftShort,
	ftInteger,
	ftLong,
	ftDouble,
	ftNumber,
	ftDate,
	ftDateMonth,
	ftDateYear,
	ftClob,
	ftBlob,
	ftBoolean;
	
	@Override
	public String toString(){
		if(this == ftString){
			return "string";
		}else if(this == ftNumber){
			return "number";
		}else if(this == ftByte){
			return "byte";
		}else if(this == ftShort){
			return "short";
		}else if(this == ftInteger){
			return "int";
		}else if(this == ftLong){
			return "long";
		}else if(this == ftDouble){
			return "double";
		}else if(this == ftDate){
			return "date";
		}else if(this == ftDateMonth){
			return "date-month";
		}else if(this == ftDateYear){
			return "date-year";
		}else if(this == ftClob){
			return "clob";
		}else if(this == ftBlob){
			return "blob";
		}else if(this == ftBoolean){
			return "boolean";
		}else {
			return "object";
		}
	}
	 
	public static TDataType parseOf(String dataType){
		if(dataType == null) {
			return ftUnkown;
		}
		if(dataType.startsWith("dt")) {
			dataType = dataType.substring(2);
		}
		if(dataType.equalsIgnoreCase("string") || dataType.equalsIgnoreCase("str")
			||dataType.equalsIgnoreCase("char")
			||dataType.equalsIgnoreCase("varchar")
			||dataType.equalsIgnoreCase("varchar2")
			||dataType.equalsIgnoreCase("nvarchar")
			||dataType.equalsIgnoreCase("nvarchar2")) {
			return ftString;
		}
		else if(dataType.equalsIgnoreCase("byte")) {
			return ftByte;
		}
		else if(dataType.equalsIgnoreCase("short")) {
			return ftShort;
		}
		else if(dataType.equalsIgnoreCase("int") ||dataType.equalsIgnoreCase("integer")) {
			return ftInteger;
		}
		else if(dataType.equalsIgnoreCase("long")) {
			return ftLong;
		}
		else if(dataType.equalsIgnoreCase("real")
				||dataType.equalsIgnoreCase("float") ||dataType.equalsIgnoreCase("double")) {
			return ftDouble;
		}
		else if(dataType.equalsIgnoreCase("number") || dataType.equalsIgnoreCase("num") || dataType.equalsIgnoreCase("numeric")) {
			return ftNumber;
		}
		else if(dataType.equalsIgnoreCase("date") ||dataType.equalsIgnoreCase("datetime")
			||dataType.equalsIgnoreCase("time")||dataType.equalsIgnoreCase("timestamp")) {
			return ftDate;
		}
		else if(dataType.equalsIgnoreCase("clob") || dataType.equalsIgnoreCase("text") || dataType.equalsIgnoreCase("mediumtext") || dataType.equalsIgnoreCase("longtext")) {
			return ftClob;
		}
		else if(dataType.equalsIgnoreCase("blob") || dataType.equalsIgnoreCase("longblob")) {
			return ftBlob;
		}else if(dataType.equalsIgnoreCase("boolean") || dataType.equalsIgnoreCase("bool")) {
			return ftBoolean;
		}else if(dataType.equalsIgnoreCase("date-month")) {
			return ftDateMonth;
		}else if(dataType.equalsIgnoreCase("date-year")) {
			return ftDateYear;
		}
		else {
			return ftString;
		}
	}
}
